package cn.appsys.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

public class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override//相当于在以前web.xml中配置的读取applicationContext.xml
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};//用于Spring的配置
    }

    @Override//相当于在以前web.xml中配置的读取springmvc-servlet.xml
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{MvcConfig.class};//专门用于MVC的配置
    }

    @Override
    protected String[] getServletMappings() { // /处理请求，不拦截jsp /* 会拦截jsp
        return new String[]{"/"};
    }

    /* 添加过滤器*/
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return new Filter[]{characterEncodingFilter};
    }
}
